<div class="layui-card">
    <div class="layui-card-header layuiadmin-card-header-auto">
        <form class="layui-form">
            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-sm" href="<?php echo \yii\helpers\Url::to(['create']) ?>" ><i class="layui-icon layui-icon-add-1"></i>添加项目</a>
                <button lay-submit lay-filter="search" class="layui-btn layui-btn-sm layui-btn-normal" ><i class="layui-icon layui-icon-search"></i>搜索</button>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="" class="layui-form-label">姓名：</label>
                    <div class="layui-input-block" style="width: 275px">
                        <input type="text" name="name" placeholder="请输入客户姓名" class="layui-input" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="" class="layui-form-label">电话：</label>
                    <div class="layui-input-block" style="width: 275px">
                        <input type="text" name="phone" placeholder="请输入客户联系电话" class="layui-input" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="" class="layui-form-label">节点：</label>
                    <div class="layui-input-block" style="width: 275px">
                        <select name="node_id">
                            <option value=""></option>
                            <?php foreach ($nodes as $n){ ?>
                                <option value="<?php echo $n['id']; ?>" ><?php echo $n['name']; ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="" class="layui-form-label">创建人：</label>
                    <div class="layui-input-block" style="width: 275px">
                        <select name="created_user_id" lay-search>
                            <option value=""></option>
                            <?php foreach ($users as $u){ ?>
                                <option value="<?php echo $u['id']; ?>" ><?php echo $u['username']; ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="" class="layui-form-label">跟进日期：</label>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="follow_at_start" name="follow_at_start" placeholder="请选择开始日期" class="layui-input" readonly >
                    </div>
                    <div class="layui-form-mid layui-word-aux">-</div>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="follow_at_end" name="follow_at_end" placeholder="请选择结束日期" class="layui-input" readonly >
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="" class="layui-form-label">下次跟进：</label>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="next_follow_at_start" name="next_follow_at_start" placeholder="请选择开始日期" class="layui-input" readonly >
                    </div>
                    <div class="layui-form-mid layui-word-aux">-</div>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="next_follow_at_end" name="next_follow_at_end" placeholder="请选择结束日期" class="layui-input" readonly >
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="" class="layui-form-label">创建日期：</label>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="created_at_start" name="created_at_start" placeholder="请选择开始日期" class="layui-input" readonly >
                    </div>
                    <div class="layui-form-mid layui-word-aux">-</div>
                    <div class="layui-input-inline" style="width: 120px">
                        <input type="text" id="created_at_end" name="created_at_end" placeholder="请选择结束日期" class="layui-input" readonly >
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-card-body">
        <table id="dataTable" lay-filter="dataTable"></table>
        <script type="text/html" id="options">
            <a href="{{d.show_url}}" class="layui-btn layui-btn-xs" ><i class="layui-icon layui-icon-template"></i>详情</a>
            <a href="{{d.edit_url}}" class="layui-btn layui-btn-xs" ><i class="layui-icon layui-icon-edit"></i>编辑</a>
            <a href="{{d.node_url}}" class="layui-btn layui-btn-xs layui-btn-normal" ><i class="layui-icon layui-icon-engine"></i>更新节点</a>
            <a href="{{d.remark_url}}" class="layui-btn layui-btn-xs layui-btn-normal" ><i class="layui-icon layui-icon-form"></i>备注</a>
            <a lay-event="destroy" class="layui-btn layui-btn-xs layui-btn-danger" ><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
    </div>
</div>


<?php
$url = yii\helpers\Url::to(['index']);
$js = <<<JS
    layui.use(['form','element','table', 'layer','laydate'],function() {
        var form = layui.form;  
        var element = layui.element;  
        var table = layui.table;  
        var layer = layui.layer;  
        var laydate = layui.laydate;  
        
        var dataTable = table.render({
            elem: '#dataTable'
            ,height: 'full-200'
            ,url: '{$url}' 
            ,page: true 
            ,toolbar: false 
            ,cols: [[ 
                {type: 'checkbox'}
                ,{field: 'name', title: '客户姓名',width:90}
                ,{field: 'sex_text', title: '性别',width:60}
                ,{field: 'phone', title: '联系电话',width:120}
                ,{field: 'other_phone', title: '其它电话'}
                ,{field: 'company', title: '公司名称'}
                ,{field: 'node_name', title: '当前节点'}
                ,{field: 'follow_at', title: '跟进时间',width: 160}
                ,{field: 'next_follow_at', title: '下次跟进时间',width: 160}
                ,{field: 'created_at', title: '创建时间',width: 160}
                ,{field: 'created_user_name', title: '创建人',width: 90}
                ,{title: '操作',toolbar:'#options',width:380}
            ]]
        });
        
        //监听工具条
        table.on('tool(dataTable)', function(obj){ 
            var data = obj.data; 
            var layEvent = obj.event;
            if(layEvent === 'destroy'){
                layer.confirm('确认删除吗？', function(index){
                    $.post(data.destroy_url,{},function(res) {
                        layer.msg(res.msg,{},function() {
                            if (res.code==0){
                                obj.del(); 
                                layer.close(index);
                            }   
                        })  
                    })
                });
            } 
        });
        
        //搜索
        form.on('submit(search)',function(data) {
            dataTable.reload({
                where: data.field,
                page: {curr:1}
            }) 
            return false;
        })
        
        laydate.render({elem: '#follow_at_start', type: 'date'})
        laydate.render({elem: '#follow_at_end', type: 'date'})
        laydate.render({elem: '#next_follow_at_start', type: 'date'})
        laydate.render({elem: '#next_follow_at_end',type: 'date'})
        laydate.render({elem: '#created_at_start',type: 'date'})
        laydate.render({elem: '#created_at_end',type: 'date'})
        
    });
JS;
$this->registerJs($js);
